APPCFG := ../google_appengine/appcfg.py

all:

.PHONY: clean
clean:
	-find . -name '*.pyc' -exec rm -f {} \;
	-find . -name 'bulkloader-*' -exec rm -f {} \;

APPCFG_UPLOAD_LOCAL = \
  $(APPCFG) \
  upload_data \
  --config=bulkloader.yaml \
  --url=http://localhost:8080/_ah/remote_api \
  --application=dev~tpeplanner \
  --kind=$(1) \
  --filename=data/converted/$(1).csv

APPCFG_DOWNLOAD_LOCAL = \
  $(APPCFG) \
  download_data \
  --config=bulkloader.yaml \
  --url=http://localhost:8080/_ah/remote_api \
  --application=dev~tpeplanner \
  --kind=$(1) \
  --filename=data/converted/$(1).csv

APPCFG_UPLOAD_REMOTE = \
  $(APPCFG) \
  upload_data \
  --config=bulkloader.yaml \
  --url=https://taipei-planner.appspot.com/_ah/remote_api \
  --application=s~taipei-planner \
  --kind=$(1) \
  --filename=data/converted/$(1).csv

.PHONY: upload-local
upload-local:
	$(call APPCFG_UPLOAD_LOCAL,Stop)
	$(call APPCFG_UPLOAD_LOCAL,Line)
	$(call APPCFG_UPLOAD_LOCAL,LineStop)
	$(call APPCFG_UPLOAD_LOCAL,HotSpotCategory)
	$(call APPCFG_UPLOAD_LOCAL,HotSpot)
	$(call APPCFG_UPLOAD_LOCAL,MrtPrice)

.PHONY: download-local
download-local:
	$(call APPCFG_DOWNLOAD_LOCAL,Stop)
	$(call APPCFG_DOWNLOAD_LOCAL,Line)
	$(call APPCFG_DOWNLOAD_LOCAL,LineStop)
	$(call APPCFG_DOWNLOAD_LOCAL,HotSpotCategory)
	$(call APPCFG_DOWNLOAD_LOCAL,HotSpot)
	$(call APPCFG_DOWNLOAD_LOCAL,MrtPrice)

.PHONY: upload-remote
upload-remote:
	$(call APPCFG_UPLOAD_REMOTE,Stop)
	$(call APPCFG_UPLOAD_REMOTE,Line)
	$(call APPCFG_UPLOAD_REMOTE,LineStop)
	$(call APPCFG_UPLOAD_REMOTE,HotSpotCategory)
	$(call APPCFG_UPLOAD_REMOTE,HotSpot)
	$(call APPCFG_UPLOAD_REMOTE,MrtPrice)
